package com.example.gitpart03;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.fragment.app.Fragment;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.shouye_second_page, container, false);

        // 获取 ListView
        ListView hotProductsList = view.findViewById(R.id.hot_products_list);

        // 模拟数据
        List<String> productList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            productList.add("产品 " + (i + 1));
        }

        // 创建 Adapter
        ArrayAdapter<String> adapter = new ArrayAdapter<>(
                getContext(),
                R.layout.chanpin_list,
                R.id.yogurt_leixing,
                productList
        );

        // 设置 Adapter
        hotProductsList.setAdapter(adapter);

        return view;
    }
}
